import React from 'react'
import {FormattedMessage} from 'react-intl'
import {Divider, Table} from 'antd'
import {Link} from 'react-router-dom'

export default class OrganizationList extends React.Component {
  render () {
    const columns = [{
      title: 'ID',
      dataIndex: 'id'
    }, {
      title: <FormattedMessage id='名称' />,
      dataIndex: 'title'
    }, {
      title: <FormattedMessage id='创建时间' />,
      dataIndex: 'createTime'
    }, {
      title: <FormattedMessage id='操作' />,
      dataIndex: 'actions',
      render: (text, record) => {
        return <div>
          <a onClick={() => this.props.openEditModal(record)}>编辑</a>
          <Divider type='vertical' />
          <Link to={`/organizations/${record.id}/admin`}>设置管理员</Link>
        </div>
      }
    }]
    const {organizationPage, currentPage} = this.props
    const {totalElements, content} = organizationPage
    const pagination = {
      current: currentPage,
      total: totalElements,
      onChange: page => this.props.changePage(page)
    }

    return <Table rowKey={record => record.id}
      columns={columns}
      dataSource={content}
      pagination={pagination}
      bordered
      className='table-center' />
  }
}
